﻿using System;
using fastCSharp;

namespace diantou.web.contest
{
    /// <summary>
    /// 问题的提交记录
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class problemJudge : problemView<problemJudge>
    {
        /// <summary>
        /// 提交记录缓存数据
        /// </summary>
        private struct cacheValue
        {
            /// <summary>
            /// 提交记录
            /// </summary>
            public diantou.dataAccess.contestJudge[] Judges;
            /// <summary>
            /// 总数量
            /// </summary>
            public int Count;
        }
        /// <summary>
        /// 提交记录客户端缓存
        /// </summary>
        private static readonly fastCSharp.sql.logCache<int, cacheValue>.array cache = new fastCSharp.sql.logCache<int, cacheValue>.array(diantou.dataAccess.tcpCall.contestJudge.onProblemJudgeLog, 4);
        /// <summary>
        /// 用户与测试提交关系集合
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private userJudge[] judges;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="problemId"></param>
        /// <param name="language"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        private bool loadView(int problemId, diantou.dataModel.judgeState.languageType language, int page)
        {
            if (base.loadView(problemId))
            {
                fastCSharp.sql.logCache<int, cacheValue>.array.value cacheValue = language == dataModel.judgeState.languageType.All && page <= 1 ? cache.Get(problemId) : default(fastCSharp.sql.logCache<int, cacheValue>.array.value);
                if (cacheValue.Value.Judges == null)
                {
                    cacheValue.Value.Judges = diantou.dataAccess.tcpCall.contestJudge.getProblem(problemId, language, OnlineJudge.JudgeValue.None, pageInfo.Size = fastCSharp.config.pub.Default.PageSize, page, out cacheValue.Value.Count);
                    cache.Set(ref cacheValue);
                }
                pageInfo.Page = page;
                pageInfo.Set(fastCSharp.config.pub.Default.PageSize, cacheValue.Value.Count);
                bool isAdmin = currentUser != null && currentUser.Permission == dataModel.user.permission.Admin;
                judges = cacheValue.Value.Judges.getArray(value => new userJudge { Judge = value, UserId = currentUserId, IsAdmin = isAdmin, Point = value.GetPoint(problem) });
                if (requestHeader.IsSearchEngine) pageInfo.Path = problem.Path.ContestJudge.ToPageString();
                return true;
            }
            return false;
        }
    }
}
